﻿using MediatR;
using RBAC.Api.Demain.ContentManagement;
using RBAC.Api.Erroc;
using RBAC.Api.Infaction;
using RBAC.Api.Read.Command.ContentManagement;
using RBAC.Api.Read.Dto.HospitalDetails;

namespace RBAC.Api.Read.CommandHandler.ContentManagement
{
    public class ShowHospitalDetailsCommandHandler : IRequestHandler<ShowHospitalDetailsCommand, APIResult<List<HospitalDetailsDto>>>
    {
        private readonly IBaseRepositry<HospitalModel> baseRepositry;
        private readonly IBaseRepositry<DepartmentModel> baseRepositry1;

        public ShowHospitalDetailsCommandHandler(IBaseRepositry<HospitalModel> baseRepositry,IBaseRepositry<DepartmentModel> baseRepositry1)
        {
            this.baseRepositry = baseRepositry;
            this.baseRepositry1 = baseRepositry1;
        }
        public Task<APIResult<List<HospitalDetailsDto>>> Handle(ShowHospitalDetailsCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<HospitalDetailsDto>> result=new APIResult<List<HospitalDetailsDto>>();
            result.Code = ResultCode.Success;
            result.Message = "获取医院详情成功";

            var list=from a in baseRepositry.GetAll()
                     join b in baseRepositry1.GetAll() on a.DepartmentsId equals b.Id
                     where a.DepartmentsId == request.DepartmentsId
                     select new HospitalDetailsDto
                     {
                         Id = a.Id,
                         Name = a.Name,
                         Address = a.Address,
                         Phone = a.Phone,
                         Introduction = a.Introduction,
                         CoverImageUrl = a.CoverImageUrl,
                         Status = a.Status,
                         DoctorNumber = a.DoctorNumber,
                         DepartmentsNumber = a.DepartmentsNumber,
                         HospitalId=b.HospitalId,
                         ParentId=b.ParentId,
                         Level=a.Level,
                         DepartmentsId=a.DepartmentsId,
                     };

                result.Data = list.ToList();


            return Task.FromResult(result);
        }
    }
}
